﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Lawyer.Web
{
    public partial class customadd : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void btnSubmit_Click(object sender, EventArgs e)
        {

            Lawyer.Model.CustomInfo user = CreateFromForm();
            Lawyer.BLL.CustomInfo bll = new Lawyer.BLL.CustomInfo();
            if (bll.Add(user))
            {
                Maticsoft.Common.MessageBox.ShowAndRedirect(this, "success！", "customlist.aspx");
            }
            else {
                Maticsoft.Common.MessageBox.ShowAndRedirect(this, "failed！", "customadd.aspx");
            }
            
            

        }
        private Lawyer.Model.CustomInfo CreateFromForm()
        {

            string FullName = this.txbFullName.Text;
            string Email = this.txbEmail.Text;
            string Sex = this.rblGender.SelectedValue;
            DateTime Birthday = DateTime.Parse(this.txbBirthday.Text);
            string City = this.txtCity.Text;
            string Telphone = this.txtTelphone.Text;
            string Fax = this.txtFax.Text;
            string Address = this.txtAddress.Text;
            string AvatarURL = this.txtAvatarURL.Text;

            Lawyer.Model.CustomInfo model = new Lawyer.Model.CustomInfo();
            model.CustomID = Guid.NewGuid().ToString();
            model.FullName = FullName;
            model.Email = Email;
            model.Sex = Sex;
            model.Birthday = Birthday;
            model.City = City;
            model.Telphone = Telphone;
            model.Fax = Fax;
            model.Address = Address;
            model.AvatarURL = AvatarURL;

            //律师只能添加personal类型的
            model.CustomType = 0;//0是preconal，1是public


            model.CreatedBy = Session["UserID"].ToString();
            model.CreatedDate = DateTime.Now;
            model.Status = 0;//0=>Normal,1=>Deleted

            model.UpdatedBy = Session["UserID"].ToString();
            model.UpdatedDate = DateTime.Now;
            return model;

        }

        //protected void btnBack_Click(object sender, EventArgs e)
        //{
        //    Response.Redirect("customlist.aspx");
        //}
    }
}
